﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Account.BLL;
using Yipusoft.Account.Model;
using Yipusoft.MeetingRecoreds.BLL;
using Yipusoft.MeetingRecoreds.Model;

public partial class Task_MeetingRecord_NewMeeting : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string DepartmentId = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
            //if (DepartmentId.Substring(4, 1) != "0" )
            //{
               
            //}
           // else
           // {
             //   Response.Write("<script>alert('只有大、中队可添加！');history.back(0);</script>");
            //    return;
           // }

            init();
        }
    }
    void SetControlVisibleTrue()
    {


        txtClassNo.Visible = true;
        lblBan.Visible = true;

        lblDD.Visible = true;
        txtPlace.Visible = true;
        trcjr.Visible = true;
        lblaqy.Visible = true;
        txtSafer.Visible = true;
    }
    void init()
    {
        int T = Convert.ToInt32(Request["T"]);
        SetControlVisibleTrue();
        if (T == 0)
        {
            lblCaption.Text = "安全防事故工作记录";
            txtClassNo.Visible = false;
            lblBan.Visible = false;

            lblDD.Visible = false;
            txtPlace.Visible = false;
            trcjr.Visible = false;
            lblYT.Text = "内容：";
        }
        if (T == 1)
        {
            lblCaption.Text = "队伍管理形势分析会";
            txtClassNo.Visible = false;
            lblBan.Visible = false;

            trzz.Visible = false;
            trCY.Visible = false;
            trcjr.Visible = false;
            lblYT.Text = "会议议题";
            lblaqy.Visible = false;
            txtSafer.Visible = false;

        }
        if (T == 2)
        {
            lblCaption.Text = "队务会";
            txtClassNo.Visible = false;
            lblBan.Visible = false;

            trzz.Visible = false;
            trCY.Visible = false;
            trcjr.Visible = false;
            lblYT.Text = "会议议题：";
            lblaqy.Visible = false;
            txtSafer.Visible = false;
        }
        if (T == 3)
        {
            lblCaption.Text = "班务会";
            txtClassNo.Visible = true;
            lblBan.Visible = true;

            trzz.Visible = false;
            trCY.Visible = false;
            trcjr.Visible = false;
            lblYT.Text = "会议内容：";
            lblaqy.Visible = false;
            txtSafer.Visible = false;
        }

        string DepartmentId = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
        DepartmentInfo department = Department.GetDepartment(DepartmentId);
        lblCity.Text = department.AliasName;
        lblDepartmentName.Text = department.ShortName;
        if (Request["ID"] != null)
        {
            Yipusoft.MeetingRecoreds.Model.MeetingRecordInfo info = MeetingRecored.GetDetail(new Guid(Request["ID"]));
            txtClassNo.Text = info.ClassNo;
            txtfHeadman.Text = info.fheadman;
            txtHeadman.Text = info.Headman;
            txtJoiner.Text = info.Joiner;
            txtMeetingContent.Text = SmartWeb.BLL.UserFun.HtmlToText(info.MeetingContent);
            txtMeetingTime.Text = info.MeetingTime.ToShortDateString();
            txtMember.Text = info.Member;
            txtPlace.Text = info.Place;
            txtPresider.Text = info.Presider;
            txtRealityCount.Text = info.RealityCount.ToString();
            txtRecorder.Text = info.Recorder;
            txtSafer.Text = info.Safer;
            txtShouldCount.Text = info.ShouldCount.ToString();
            txtSubject.Text = info.Subject;
            department = Department.GetDepartment(info.DepartmentId);
            lblCity.Text = department.AliasName;
            lblDepartmentName.Text = department.ShortName;
        }
        else
        {
            if (T == 0)
            {
                string where = "DepartmentID='" + DepartmentId + "' and MeetingType=0 ";
                MeetingRecordInfo first = MeetingRecored.GetList(where, 10000, 0).FirstOrDefault();
                if (first != null)
                {
                    txtSafer.Text = first.Safer;
                    txtHeadman.Text = first.Headman;
                    txtfHeadman.Text = first.fheadman;
                    txtMember.Text = first.Headman;
                }
            }
        }

    }

    protected void btnSave_Click(object sender, EventArgs e)
    {

        int ShouldCount = 0;
        if (!int.TryParse(txtShouldCount.Text, out ShouldCount))
        {
            txtprompt.Text = "提示：应到人数必须为数字！";
            return;
        }
        int RealityCount = 0;
        if (!int.TryParse(txtRealityCount.Text, out RealityCount))
        {
            txtprompt.Text = "提示：实到人数必须为数字！";
            return;
        }
        try
        {
            int T = Convert.ToInt32(Request["T"]);
            string DepartmentId = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
            if (Request["ID"] != null)
            {
                //修改

                Yipusoft.MeetingRecoreds.Model.MeetingRecordInfo info = MeetingRecored.GetDetail(new Guid(Request["ID"]));
                info.ClassNo = txtClassNo.Text;
                info.DepartmentId = DepartmentId;
                info.DepartmentName = lblDepartmentName.Text;
                info.fheadman = txtfHeadman.Text;
                info.Headman = txtHeadman.Text;

                info.Joiner = txtJoiner.Text;
                info.MeetingContent = SmartWeb.BLL.UserFun.TextToHtml(txtMeetingContent.Text);
                info.MeetingTime = Convert.ToDateTime(txtMeetingTime.Text);
                info.MeetingType = T;
                info.Member = txtMember.Text;
                info.Place = txtPlace.Text;
                info.Presider = txtPresider.Text;
                info.RealityCount = Convert.ToInt32(txtRealityCount.Text);
                info.Recorder = txtRecorder.Text;
                info.Safer = txtSafer.Text;
                info.SetTime = DateTime.Now;
                info.SetUserId = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).UserID;
                info.ShouldCount = Convert.ToInt32(txtShouldCount.Text);
                info.Subject = txtSubject.Text;

                MeetingRecored.Update(info);

            }
            else
            {
                //添加

                Yipusoft.MeetingRecoreds.Model.MeetingRecordInfo info = new MeetingRecordInfo();
                info.ClassNo = txtClassNo.Text;
                info.DepartmentId = DepartmentId;
                info.DepartmentName = lblDepartmentName.Text;
                info.fheadman = txtfHeadman.Text;
                info.Headman = txtHeadman.Text;
                info.Id = Guid.NewGuid();
                info.Joiner = txtJoiner.Text;
                info.MeetingContent = SmartWeb.BLL.UserFun.TextToHtml(txtMeetingContent.Text);
                info.MeetingTime = Convert.ToDateTime(txtMeetingTime.Text);
                info.MeetingType = T;
                info.Member = txtMember.Text;
                info.Place = txtPlace.Text;
                info.Presider = txtPresider.Text;
                info.RealityCount = Convert.ToInt32(txtRealityCount.Text);
                info.Recorder = txtRecorder.Text;
                info.Safer = txtSafer.Text;
                info.SetTime = DateTime.Now;
                info.SetUserId = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).UserID;
                info.ShouldCount = Convert.ToInt32(txtShouldCount.Text);
                info.Subject = txtSubject.Text;
                info.Id = Guid.NewGuid();
                Guid id = MeetingRecored.Insert(info);
                if (id != Guid.Empty)
                {
                    txtprompt.Text = "提示：添加不成功！" ;
                }

            }
            Response.Redirect("MeetingList.aspx");
        }
        catch (Exception ex)
        {
            txtprompt.Text = "提示：" + ex.Message;
        }

    }
    protected void btnCancal_Click(object sender, EventArgs e)
    {
        Response.Redirect("MeetingList.aspx");
    }
}
